---
title: Forecasting Quarterly House Sales with StatsForecast
sidebarTitle: House Sales with StatsForecast
---

## Introduction

In this tutorial, we introduce Nixtla’s StatsForecast integration which offers numerous univariate time series forecasting models optimized for high performance and scalability. We’ll go through an example to predict the real estate sales.

## Prerequisites

### MindsDB Setup

One way is to sign up for an account at [MindsDB Cloud](https://cloud.mindsdb.com/). It is a convenient option as it doesn’t require any installation procedures. You can find the details [here](/setup/cloud).

Alternatively, visit our docs and follow the instructions to manually set up a local instance of MindsDB via [Docker](/setup/self-hosted/docker) or [pip](/setup/self-hosted/pip/source). You can also set up MindsDB on AWS following [this instruction set](https://aws.amazon.com/marketplace/pp/prodview-2nmhvskydmyrw).

### Creating an ML Engine

Please note that before using the StatsForecast engine, you should create it with the below command:

```sql
CREATE ML_ENGINE statsforecast
FROM statsforecast;
```

You can check the available engines with this command:

```sql
SHOW ML_ENGINES;
```

If you see the StatsForecast engine on the list, you are ready to follow the tutorials.

## Tutorial

### Connecting the Data

In this tutorial, we take our [House Sales tutorial](/sql/tutorials/house-sales-forecasting) and redo it using the StatsForecast engine.

We use a table from our MySQL public demo database, so let’s start by connecting MindsDB to it:

```sql
CREATE DATABASE mysql_demo_db
WITH ENGINE = 'mysql',
PARAMETERS = {
    "user": "user",
    "password": "MindsDBUser123!",
    "host": "db-demo-data.cwoyhfn6bzs0.us-east-1.rds.amazonaws.com",
    "port": "3306",
    "database": "public"
};
```

Now that we’ve connected our database to MindsDB, let’s query the data to be used in the example:

```sql
SELECT *
FROM mysql_demo_db.house_sales
LIMIT 3;
```

Here is the output:

```sql
+----------+--------------------------+-----+--------+
|saledate  |house_price_moving_average|type |bedrooms|
+----------+--------------------------+-----+--------+
|30/09/2007|441854                    |house|2       |
|31/12/2007|441854                    |house|2       |
|31/03/2008|441854                    |house|2       |
+----------+--------------------------+-----+--------+
```

The `house_sales` table stores quarterly house price moving averages per property.

### Creating a Model

Let's create a model table to predict the house price moving average values:

```sql
CREATE MODEL mindsdb.house_sales_predictor
FROM mysql_demo_db
  (SELECT * FROM house_sales)
PREDICT house_price_moving_average
ORDER BY saledate
GROUP BY bedrooms, type
WINDOW 8
HORIZON 4
USING ENGINE = 'statsforecast';
```

The sytax is the same as in original tutorial. But here, we add the `USING` clause that specifies the ML engine used to make predictions.

We can check the training status with the following query:

```sql
DESCRIBE house_sales_predictor;
```

### Making Predictions

Once the model status is `complete`, the behavior is the same as with any other AI table – you can query for batch predictions by joining it with a data table:

```sql
SELECT m.saledate AS date, m.house_price_moving_average AS forecast
FROM mindsdb.house_sales_predictor AS m
JOIN mysql_demo_db.house_sales AS t
WHERE t.saledate > LATEST
AND t.type = 'house'
AND t.bedrooms = 2
LIMIT 3;
```

Here is the output data:

```sql
+----------------------------+----------+
| date                       | forecast |
+----------------------------+----------+
| 2019-12-31 00:00:00.000000 | 510712   |
| 2020-03-31 00:00:00.000000 | 510712   |
| 2020-06-30 00:00:00.000000 | 510712   |
+----------------------------+----------+
```

## What's Next?

Have fun while trying it out yourself!

- Bookmark [MindsDB repository on GitHub](https://github.com/mindsdb/mindsdb).
- Sign up for a free [MindsDB account](https://cloud.mindsdb.com/register).
- Engage with the MindsDB community on
  [Slack](https://mindsdb.com/joincommunity) or
  [GitHub](https://github.com/mindsdb/mindsdb/discussions) to ask questions and
  share your ideas and thoughts.

If this tutorial was helpful, please give us a GitHub star
[here](https://github.com/mindsdb/mindsdb).
